package com.article.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.article.entity.User;
import com.article.service.IUserService;

@SuppressWarnings("serial")
public class UserAction extends BaseAction implements ServletRequestAware {
	private HttpServletRequest request;
	private String userName;
	private String password;
	private IUserService userService;

	public String execute() {
		System.out.println("用户登录：" + userName + "," + password);
		User user = userService.checkLogin(userName, password);
		if (user != null) {
			request.getSession().setAttribute("user", user);
			System.out.println("登录成功！");
			return SUCCESS;
		}
		System.out.println("登录失败！");
		return INPUT;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		request = arg0;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

}
